<template>
  <h1>El-表格组件</h1>
  <el-table :data="tableData">
    <el-table-column prop="date" label="日期" width="180" />
    <el-table-column prop="name" label="姓名" width="180" />
    <el-table-column prop="address" label="地址" />
  </el-table>
  <el-table :data="arr">
    <el-table-column label="编号" type="index" width="60"></el-table-column>
    <el-table-column prop="name" label="姓名" width="180"></el-table-column>
    <el-table-column prop="salary" label="工资" width="180"></el-table-column>
    <el-table-column prop="job" label="岗位"></el-table-column>
    <el-table-column>
      <!--表格中添加非文本的自定义内容,都需要使用template标签包裹
      #default="scope" VUE3的固定写法,scope起到了数据传递的作用,可以从scope中获取表格中的数据
      scope.$index被删除元素的下标 scope.row当前行对应的对象-->
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <h3>表格</h3>
  <el-table :data="arr" style="width: 430px;margin: 0 auto;">
    <el-table-column v-for="col in tableColumns" v-bind="col"></el-table-column>
  </el-table>
</template>

<script setup>
import {ref} from "vue";

const del = (i,emp)=>{
  if(confirm('您确认要删除'+emp.name+'吗?')){
    arr.value.splice(i,1);
  }
}

const arr = ref([
    {name:"张三",salary:"5000",job:"销售员"},
    {name:"李四",salary:"6000",job:"维修员"},
    {name:"王五",salary:"7000",job:"护林员"},
    {name:"赵六",salary:"8000",job:"程序猿"}
]);
const tableColumns = ref([
  {label:"编号",type:'index',width:60},
  {label:"姓名",prop:'name'},
  {label:"工资",prop:'salary'},
  {label:"岗位",prop:'job'}
]);
const tableData = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
]
</script>

<style scoped>

</style>